// 导入全部vue组件 进行匹配
// const viteAllComponents = import.meta.glob("../**/*.vue")
// 导入pages下全部vue组件 进行匹配
const viteAllComponents = import.meta.glob("../pages/**/*.vue")

// 递归处理路由
function filterRouter(tree) {
    tree.forEach(c => {
        if (c.component == 'Layout') {
            c.component = _ => import('@/views/layout/index.vue')
        }
        else if (c.component == 'ParentView') {
            c.component = _ => import('@/views/parentView.vue')
        }
        else {
            c.component = viteAllComponents[`../pages/${c.component}.vue`]
        }
        c.children && c.children.length && filterRouter(c.children)
    })
    return tree
}

// 注册路由
import router from './index'
export default function (tree) {
    filterRouter(tree).forEach(c => {
        router.addRoute(c)
    })
}


